package 牛客_面试必刷.Month07.day11;

import java.util.EmptyStackException;
import java.util.Stack;

public class 包含min函数的栈 {

    Stack<Integer> s1 = new Stack<>();
    Stack<Integer> s2 = new Stack<>();

    public void push(int node) {
        s1.push(node);
        if(s2.isEmpty() || s2.peek() > node){
            s2.push(node);
        }else{
            s2.push(s2.peek());
        }
    }

    public void pop() {
        s1.pop();
        s2.pop();
    }

    public int top() {
        return s1.peek();
    }

    public int min() {
        return s2.peek();
    }


}

/*

    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();

    public void push(int node) {

        stack1.push(node);
        if (stack2.peek() > node || stack2.isEmpty()) {
            stack2.push(node);
        } else {
            stack2.push(stack2.peek());
        }
    }

    public void pop() {
        stack1.pop();
        stack2.pop();
    }

    public int top() {
        if (stack1.isEmpty()) {
            throw new EmptyStackException();
        }
        return stack1.peek();
    }

    public int min() {
        return stack2.peek();
    }

 */
